<script setup lang="ts">
import type { DiskIOStat } from '@/types/disk'

interface Props {
  diskIOStat: DiskIOStat
}

defineProps<Props>()
</script>

<template>
  <div class="disk-io-stats-card">
    <div class="disk-io-stats-header">
      <span class="disk-name">{{ diskIOStat.name }}</span>
      <span class="disk-status" :class="{ active: diskIOStat.iops_in_progress > 0 }">
        {{ diskIOStat.iops_in_progress > 0 ? '活跃' : '空闲' }}
      </span>
    </div>

    <div class="disk-io-stats-grid">
      <div class="stat-group">
        <div class="stat-item">
          <span class="stat-label">读取操作</span>
          <span class="stat-value">{{ Number(diskIOStat.read_count).toLocaleString() }} 次</span>
          <span class="stat-detail">{{ diskIOStat.read_bytes }}</span>
        </div>

        <div class="stat-item">
          <span class="stat-label">写入操作</span>
          <span class="stat-value">{{ Number(diskIOStat.write_count).toLocaleString() }} 次</span>
          <span class="stat-detail">{{ diskIOStat.write_bytes }}</span>
        </div>
      </div>

      <div class="stat-group">
        <div class="stat-item">
          <span class="stat-label">I/O时间</span>
          <span class="stat-value">{{ diskIOStat.io_time }}</span>
        </div>

        <div class="stat-item">
          <span class="stat-label">加权I/O</span>
          <span class="stat-value">{{ diskIOStat.weighted_io }}</span>
        </div>

        <div class="stat-item">
          <span class="stat-label">进行中IOPS</span>
          <span class="stat-value" :class="{ highlight: diskIOStat.iops_in_progress > 0 }">
            {{ diskIOStat.iops_in_progress }}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.disk-io-stats-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1.5rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.disk-io-stats-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.disk-io-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.disk-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #ffffff;
}

.disk-status {
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.disk-status.active {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.disk-status:not(.active) {
  background: rgba(156, 163, 175, 0.1);
  color: #9ca3af;
  border: 1px solid rgba(156, 163, 175, 0.2);
}

.disk-io-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.stat-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.875rem;
  color: #9ca3af;
  font-weight: 500;
}

.stat-value {
  font-size: 1.125rem;
  font-weight: 600;
  color: #ffffff;
}

.stat-value.highlight {
  color: #f59e0b;
}

.stat-detail {
  font-size: 0.875rem;
  color: #9ca3af;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .disk-io-stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
</style>
